package com.security.securitydemo.service;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.security.securitydemo.entity.SysUser;
import com.security.securitydemo.dao.SysUserDao;

@Service
public class SysUserService implements UserDetailsService {

    @Resource
    private SysUserDao sysUserDao;

    public int insert(SysUser pojo){
        return sysUserDao.insert(pojo);
    }

    public int insertSelective(SysUser pojo){
        return sysUserDao.insertSelective(pojo);
    }

    public int insertList(List<SysUser> pojos){
        return sysUserDao.insertList(pojos);
    }

    public int update(SysUser pojo){
        return sysUserDao.update(pojo);
    }


    @Override
    public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException {
        SysUser user = sysUserDao.findByUsername(s);
        if(null==user) {
            throw new UsernameNotFoundException("用户名不存在");
        }
        return user;
    }
}
